//
//  NewsDetailViewController.m
//  MyAppDemo
//
//  Created by 千锋 on 15/12/5.
//  Copyright (c) 2015年 Aike. All rights reserved.
//

#import "NewsDetailViewController.h"

#import "NewsDetailModel.h"

#import "GDataXMLNode.h"

@interface NewsDetailViewController ()<UIWebViewDelegate>
{
    NewsDetailModel * _model;
}

@end

@implementation NewsDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.title = @"有关详情";
    [self requestData];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.view reloadInputViews];
}
-(void)requestData{
    //创建URL
    NSString * newsDetailURL = self.newsDetail;
    //创建请求
    NSURLRequest * request = [NSURLRequest requestWithURL:[NSURL URLWithString:newsDetailURL]];
    //3.通过异步请求
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        _model = [NewsDetailModel parseXMLWithData:data];
        //获取屏幕的宽度
        CGSize screenSize = [UIScreen mainScreen].bounds.size;
        UIWebView * webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 65, screenSize.width, screenSize.height-114)];
        //使用UIWebView
        //创建请求
        NSURLRequest * request = [NSURLRequest requestWithURL:[NSURL URLWithString:newsDetailURL]];
        [webView loadRequest:request];
        webView.paginationMode = UIWebPaginationModeUnpaginated;
        [webView loadHTMLString:[NSString stringWithFormat:@"%@",_model.body] baseURL:nil];
        [self.view addSubview:webView];
        webView.delegate = self;
    }];
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
